import req from "../req.js";

//更新用户笔记顶级目录
export function userTopdirUpadata( ldata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/note/changeTopDir",
            method:"post",
            data: ldata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });
}

//获取用户顶级目录
export function getUserTopdir( ldata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/note/getdir",
            method:"post",
            data: ldata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });
}

//添加子目录
export function setInnerDir( idata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/note/addInnerDir",
            method:"post",
            data: idata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });
}

//获取子目录
export function getInnerDirContent( idata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/note/getInnerDir",
            method:"post",
            data: idata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });  
}

//删除目录
export function removeDeratory( idata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/note/rmDir",
            method:"post",
            data: idata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });  
}

//创建文章
export function createArticle( adata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/note/mkFile",
            method:"post",
            data: adata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });  
}

//重命名目录
export function reNameDir( rdata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/note/rename",
            method:"post",
            data: rdata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });  
}

//保存编辑文章的内容
export function savrArticle( sdata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/note/saveArticle",
            method:"post",
            data: sdata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });  
}

//获取文章内容
//保存编辑文章的内容
export function getArticle( adata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/note/getArt",
            method:"post",
            data: adata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });  
}